package com.yun.datastructure.tree.binarytree;

import com.yun.datastructure.tree.binarytree.domain.TreeNode;

public class TreeTraversal {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(
                new TreeNode(new TreeNode(4), 2, null),
                1,
                new TreeNode(new TreeNode(5), 3, new TreeNode(6))
        );
    }

    private static void colorPrintln(String origin, int color) {
        System.out.printf("\033[%dm%s\033[0m%n", color, origin);
    }

    //前序遍历
    static void preOrder(TreeNode node) {
        if (node == null) {
            return;
        }
        System.out.print(node.val + "\t");//值
        preOrder(node.left);//左
        preOrder(node.right);//右
    }

    static void inOrder(TreeNode node) {
        if (node == null) {
            return;
        }
        preOrder(node.left);//左
        System.out.print(node.val + "\t");//值
        preOrder(node.right);//右
    }

    static void postOrder(TreeNode node) {
        if (node == null) {
            return;
        }
        preOrder(node.left);//左
        preOrder(node.right);//右
        System.out.print(node.val + "\t");//值
    }
}
